<?php
namespace Admin\Controller;
use Think\Controller;
class SeoController extends CommonController {

	//设置SEO相关信息
	public function index(){
		$sitesettings = M('config');
		$res = $sitesettings -> select();
		$set = array();
		foreach($res as $key => $value){
		    $set[ $res[$key]['key'] ] = $value['value'];
		}
		$this -> assign('keywords',$set['keywords']);
		$this -> assign('siteinfo',$set['siteinfo']);
		$this -> assign('sitename',$set['sitename']);
		$this -> assign('websiteurl',$set['websiteurl']);
		$this -> assign('icoimg',$set['icoimg']);
		//以瀑布流形式 已加载的相片不会再被加载
		$this -> assign('test','网站设置');
		$this->display();
	}

	//设置网站相关信息处理
	public function ajaxseo(){
		//这里请使用ajax访问
		if (IS_AJAX) {
			$sitesettings = M();
			//遍历修改数据库内容
			foreach ($_POST as $key => $value) {
				$sitesettings -> query("UPDATE `zz_config` SET `value`='".$value."' WHERE `key` = '".$key."'");
			}
		}else{
			$this -> error('非法操作');
		}
	}

	//设置网站图片的处理页面
	public function icoimg(){
		//实例化config类
		$config = M('config');
		$res = $config -> field('value')  -> where("`key`='icoimg'") -> select();
		// echo $config -> _sql();
		$res = $res[0]['value'];
		//删除之前的图片
		unlink('./Public'.$res);
		$res = Uploads('icoimg','icoimg');
		//将新的图标路径存如数据库
		$data['value'] = $res;
		$test = $config -> where("`key`='icoimg'") -> save($data);
		// echo $config -> _sql();die;
		if ($test) {
			$this -> success('网站图标修改成功');
		}else{
			$this -> success('网站图标修改失败');
		}
	}

}
